<?php

require_once 'database.php';

//Included to return JSON
header("content-type:application/json");

$objReturn = array();

//user to login
$strUsername = $_POST['username'];
//password to check
$strPassword = $_POST['password'];

//Authenticate user

//Determine if user exists
$dbUsers = mysql_query("SELECT * FROM account WHERE username= '$strUsername' AND password= '$strPassword'", $dbLocalhost)
or die("Problem reading table: " . mysql_error());

$intUsersFound = mysql_num_rows($dbUsers);
//If not add user to DB and login the user

if($intUsersFound == 0){
	//Return error message 'username already exists!'
	$objReturn['code'] = 'ERROR';
	$objReturn['message'] = "Incorrect username/password!";
} else {

	//Handle login
	//start the session
	session_start();
	$_SESSION['user'] = $strUsername;

	$objReturn['code'] = 'SUCCESS';
}

echo json_encode($objReturn);



//Store user login info in "session"?

?>